package jsyf.oa.web.capital;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.capital.FlowFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMethod;

import java.text.ParseException;
import java.util.List;

/**
 * Created by houtailei on 2018/2/25.
 */
@Api(value = "T_CPT_FLOW接口", description = "T_CPT_FLOW接口")
@Controller
@RequestMapping("/flow")
public class FlowController {
    @Resource
    private FlowFacade flowFacade;

    @ApiOperation(value = "获取银行收入支出流水", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getBankCardListAndFlowList.json", method = RequestMethod.POST)
    public void getBankCardListAndFlowList(HttpServletResponse response, @RequestBody String jsonData) throws ParseException {
        JSONObject obj = JSON.parseObject(jsonData);
        List<JSONObject> record = flowFacade.getBankCardListAndFlowList(obj.getString("fkCompanyId"),obj.getString("date"));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrTimeRespond(record));
    }

    @ApiOperation(value = "查看收入支出流水", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getFlowList.json", method = RequestMethod.POST)
    public void getFlowList(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = flowFacade.getFlowList(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
    }


    @ApiOperation(value = "修改流水", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'流水id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/updateFlow.json", method = RequestMethod.POST)
    public void updateFlow(HttpServletResponse response, @RequestBody String jsonData) {
        String id = flowFacade.updateFlow(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }

    @ApiOperation(value = "作废收入支出流水", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'流水id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/detailFlow.json", method = RequestMethod.POST)
    public void updateBankCard(HttpServletResponse response, @RequestBody String jsonData) {
        String id = flowFacade.detailFlow(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }
    @ApiOperation(value = "删除收入支出流水", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'id':'流水id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/removeFlow.json", method = RequestMethod.POST)
    public void removeFlow(HttpServletResponse response, @RequestBody String jsonData) {
        String id = flowFacade.removeFlow(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }

    @ApiOperation(value = "收入记录", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/addFlow.json", method = RequestMethod.POST)
    public void addFlow(HttpServletResponse response, @RequestBody String jsonData) {
        String id = flowFacade.addFlow(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }

    @ApiOperation(value = "内部转账", notes = "")
    @ApiImplicitParam(name = "jsonData", value = "{'userId':'人员id'}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/transferAccounts.json", method = RequestMethod.POST)
    public void transferAccounts(HttpServletResponse response, @RequestBody String jsonData) {
        String id = flowFacade.transferAccounts(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id.toString()));
    }


}
